<html>
<head>
    <script type="text/javascript" src="../libjs/Perl6/MetaModel.js"></script>
    <script type="text/javascript">
        require.INC = "../inc";    
        require('Test.Builder');
        require('Test.More');        

        require.INC = "../libjs";    
        require('Perl6.Attribute');             
        require('Perl6.Method');     
        require('Perl6.MetaClass');     
        require('Perl6.Class');
        require('Perl6.Instance');        
        require('Perl6.Object');
    </script>     
</head>
<body>
<pre id='test'><script type="text/javascript">

plan({ 'tests' : 10 });

var obj = call_method(Perl6.Object, 'new');
isaOK(obj, 'Perl6.Instance');

ok(obj.isa('Perl6::Object'), '... this is an instance of Perl6::Object');

// now extend it

var Foo = new Perl6.Class('Foo', {
    'is' : [ Perl6.Object ],
    'instance' : {
        'attrs' : [ '$.bar' ],
        'methods' : {
            'bar' : function (self, value) {
                return iv('$.bar', value);
            }
        }
    }
});
isaOK(Foo, 'Perl6.Class');

ok(Foo.isa('Foo'), '... Foo isa Foo');
ok(Foo.isa('Perl6::Object'), '... Foo isa Perl6::Object');

var foo = call_method(Foo, 'new', { '$.bar' : 'Foo.bar' });
isaOK(foo, 'Perl6.Instance');

ok(foo.isa('Foo'), '... foo isa Foo');
ok(foo.isa('Perl6::Object'), '... foo isa Perl6::Object');

is(call_method(foo, 'bar'), 'Foo.bar', '... our attributes stored correctly through BUILD');

call_method(foo, 'bar', 'Changed this!');

is(call_method(foo, 'bar'), 'Changed this!', '... our attributes stored correctly bar()');


</script></pre>
</body>
</html>
